import type { ComponentPublicInstance, ExtractPropTypes, PropType } from "vue";

export interface FieldNames {
  list: string;
  total: string;
}

export enum DataSourceMode {
  Loadmore = "Loadmore",
  Pagination = "Pagination",
}

export const basicTableProps = {
  params: {
    type: Object as PropType<Record<string, unknown>>,
    default: () => ({}),
  },
  request: {
    type: Function,
    default: null,
  },
  // 是否初始化时发起请求，关闭则需要手动调用请求方法
  isInitRequest: {
    type: Boolean,
    default: true,
  },
  fieldNames: {
    type: Object as PropType<Partial<FieldNames>>,
    default: () => ({
      list: "list",
      total: "total",
    }),
  },
  dataSourceMode: {
    type: String as PropType<DataSourceMode>,
    default: DataSourceMode.Loadmore,
  },
  defaultPageSize: {
    type: Number,
    default: 20,
  },
  containerClass: {
    type: String,
    default: "",
  },
  contentClass: {
    type: String,
    default: "",
  },
  paginationClass: {
    type: String,
    default: "",
  },
  loadMoreClass: {
    type: String,
    default: "bg-hex-232829",
  },
};

export type BasicTableEmits<T> = {
  requestEnd: [dataSource: T[]];
};

export type BasicTableProps = ExtractPropTypes<typeof basicTableProps>;
export type BasicTableExpose = {
  getDataSource: () => void;
  resetQuery: () => void;
};

export type BasicTableInstance = ComponentPublicInstance<
  BasicTableExpose,
  BasicTableProps
>;
